package com.gorkr.bio.thread_pool;

import java.util.concurrent.*;

/**
 * @author gorkr
 * @date 2022/05/31 00:23
 **/
public class HandlerSocketServerPool {
    /*
    线程池的创建方法 5 中 1-4特定的,5自定义

     */
    public static void main(String[] args) {
        // 内置方式
        Executors.newCachedThreadPool();
        Executors.newFixedThreadPool(3);
        Executors.newSingleThreadExecutor();
        Executors.newScheduledThreadPool(3);
        // 自定义方式 通常使用这种方式
        new ThreadPoolExecutor(2,4,120,TimeUnit.SECONDS,new ArrayBlockingQueue<>(5));
    }

    // 存储线程池对象
    private ExecutorService executorService;

    /**
     *
     * @param maxThreadNum 最大线程数
     * @param queueSize 阻塞队列大小
     */
    public  HandlerSocketServerPool(int maxThreadNum, int queueSize){
        executorService = new ThreadPoolExecutor(3,maxThreadNum,120, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(queueSize));
    }

    public void execute(Runnable target){
        executorService.execute(target);
    }

}
    